package io.renren.modules.customer.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.renren.common.annotation.SysLog;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.customer.entity.BatchApplicationEntity;
import io.renren.modules.customer.service.BatchApplicationService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author Sean
 * @email seanla@qq.com
 * @date 2020-03-17 16:36:45
 */
@RestController
@RequestMapping("/customer/batchapplication")
public class BatchApplicationController extends AbstractController {

    private static final Logger LOGGER = LoggerFactory.getLogger(BatchApplicationController.class);

    @Autowired
    private BatchApplicationService batchApplicationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("customer:batchapplication:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = batchApplicationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("customer:batchapplication:info")
    public R info(@PathVariable("id") Long id){
		BatchApplicationEntity batchApplication = batchApplicationService.getById(id);

        return R.ok().put("batchApplication", batchApplication);
    }

    /**
     * 保存
     */
    @SysLog("新增进件")
    @RequestMapping("/save")
    @RequiresPermissions("customer:batchapplication:save")
    public R save(@RequestBody BatchApplicationEntity batchApplication){
        ValidatorUtils.validateEntity(batchApplication);
		batchApplicationService.save(batchApplication);
        batchApplication.setCreateUserId(getUserId());
        batchApplication.setCreateTime(new Date());
        return R.ok();
    }

    /**
     * 修改
     */
    @SysLog("修改进件")
    @RequestMapping("/update")
    @RequiresPermissions("customer:batchapplication:update")
    public R update(@RequestBody BatchApplicationEntity batchApplication){
        ValidatorUtils.validateEntity(batchApplication);
		batchApplicationService.updateById(batchApplication);
        return R.ok();
    }

    /**
     * 删除
     */
    @SysLog("删除进件")
    @RequestMapping("/delete")
    @RequiresPermissions("customer:batchapplication:delete")
    public R delete(@RequestBody Long[] ids){
		batchApplicationService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
